import 'package:english_words/english_words.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';

class ScaffoldRoute extends StatefulWidget {
  const ScaffoldRoute({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() => _ScaffoldRouteState();
}

class _ScaffoldRouteState extends State<ScaffoldRoute> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Scaffold'),
        actions: [
          IconButton(onPressed: () {}, icon: const Icon(Icons.share)),
        ],
      ),
      drawer: const MyDrawer(),
      bottomNavigationBar: BottomAppBar(
        color: Colors.white54,
        shape: const CircularNotchedRectangle(),
        child: Row(
          children: <Widget>[
            IconButton(
                icon: SvgPicture.asset("assets/svgs/a-01nvxingjiaose.svg"),
                onPressed: () {}),
            const SizedBox(), //中间位置空出
            IconButton(
                icon: SvgPicture.asset("assets/svgs/a-10nvxingjiaose.svg"),
                onPressed: () {}),
          ],
          mainAxisAlignment: MainAxisAlignment.spaceAround,
        ),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      floatingActionButton: FloatingActionButton(
          child: const Icon(Icons.arrow_back_sharp),
          onPressed: () => Navigator.of(context).pushNamed("/chapter5")),
      body: SingleChildScrollView(
        child: Builder(
          builder: (b) {
            var children = <Widget>[];
            for (var i = 0; i < 20; i++) {
              children.add(ListTile(title: Text(WordPair.random().asString)));
            }
            return Column(children: children);
          },
        ),
      ),
    );
  }
}

class MyDrawer extends StatelessWidget {
  const MyDrawer({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: MediaQuery.removePadding(
        context: context,
        //移除抽屉菜单顶部默认留白
        removeTop: true,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding: const EdgeInsets.only(top: 30),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                verticalDirection: VerticalDirection.up,
                children: <Widget>[
                  Padding(
                    padding: const EdgeInsets.symmetric(horizontal: 16.0),
                    child: ClipOval(
                      child: Image.asset(
                        "assets/images/avatar.png",
                        width: 60,
                      ),
                    ),
                  ),
                  const SizedBox(width: 10),
                  const Text(
                    "Wendux",
                    style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
                  ),
                ],
              ),
            ),
            Expanded(
              child: ListView(
                children: const [
                  ListTile(
                      title: Text("个人信息"), leading: Icon(Icons.info_outline)),
                  ListTile(
                      title: Text("我的订单"),
                      leading: Icon(Icons.bookmark_border_outlined)),
                  ListTile(title: Text("修改密码"), leading: Icon(Icons.password)),
                  ListTile(title: Text("退出登录"), leading: Icon(Icons.logout)),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
